﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 渐变.user_Form
{
    public partial class user_editInformation : Form
    {
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 0x84:
                    base.WndProc(ref m);
                    if ((int)m.Result == 0x1)
                        m.Result = (IntPtr)0x2;
                    return;
            }

            base.WndProc(ref m);
        }

        /// <summary>
        /// 设置窗体的Region
        /// </summary>
        public void SetWindowRegion()
        {
            GraphicsPath FormPath;
            Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
            FormPath = GetRoundedRectPath(rect, 50);
            this.Region = new Region(FormPath);

        }
        /// <summary>
        /// 绘制圆角路径
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="radius"></param>
        /// <returns></returns>
        private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
        {
            int diameter = radius;
            Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
            GraphicsPath path = new GraphicsPath();

            // 左上角
            path.AddArc(arcRect, 180, 90);

            // 右上角
            arcRect.X = rect.Right - diameter;
            path.AddArc(arcRect, 270, 90);

            // 右下角
            arcRect.Y = rect.Bottom - diameter;
            path.AddArc(arcRect, 0, 90);

            // 左下角
            arcRect.X = rect.Left;
            path.AddArc(arcRect, 90, 90);
            path.CloseFigure();//闭合曲线
            return path;
        }
        public user_editInformation()
        {
           // m_aeroEnabled = false;
            this.FormBorderStyle = FormBorderStyle.None;
            InitializeComponent();
        }

        private void user_editInformation_Load(object sender, EventArgs e)
        {
            SetWindowRegion();
            txtaddress.Text = this.eaddress;
            txtphone.Text = this.ephone;
            
        }

        private void btnCnacel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public string epname { get; set; }
        public string ephone { get; set; }
        public string eaddress { get; set; }
        public string epassword { get; set; }

        private void txtpwd_KeyUp(object sender, KeyEventArgs e)
        {
            if (this.epassword == txtpwd.Text)
            {
                pwdTip.Text = "密码输入正确";
                pwdTip.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                //原密码输入不正确
                pwdTip.Text = "原密码输入不正确";
                pwdTip.ForeColor = System.Drawing.Color.Red;

            }
        }

        private void btnSub_Click(object sender, EventArgs e)
        {
            if (pwdTip.ForeColor == System.Drawing.Color.Green)
            {
                //可以修改
                string sql = "update uUser set uPhone=@uPhone,uAddress=@uAddress where uUsername = @uUsername";
                SqlParameter[] ps =
                {
                    new SqlParameter("@uPhone",txtphone.Text),
                    new SqlParameter("@uAddress",txtaddress.Text),
                    new SqlParameter("@uUsername",this.epname),
                    };
                int res = DBHelper.ExecuteNonQuery(sql, ps);
                if (res > 0)
                {
                    this.ShowSuccessTip("修改成功");
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    this.ShowErrorTip("修改失败");
                    
                }
            }
            else
            {
                if (pwdTip.ForeColor == System.Drawing.Color.Red)
                {
                    this.ShowErrorTip("原密码不正确！");
                }
                

            }
        }
    }
}
